﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtStartYear.Text = "1890";
            txtEndYear.Text = DateTime.Now.Year.ToString();
        }

        private void btnDetermine_Click(object sender, EventArgs e)
        {
            int startYear, endYear;
            // 清空多行文本框
            txtLeapYears.Text = "";

            // 尝试解析起始年份和结束年份
            if (int.TryParse(txtStartYear.Text, out startYear) && int.TryParse(txtEndYear.Text, out endYear))
            {
                // 遍历指定年份范围
                for (int i = startYear; i <= endYear; i++)
                {
                    // 判断是否为闰年：能被 4 整除但不能被 100 整除，或者能被 400 整除
                    if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
                    {
                        // 将闰年添加到多行文本框，用制表符分隔
                        txtLeapYears.Text += i.ToString() + "\t";
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入有效的年份！");
            }
        }
    }
}
